<template>
  <div>
    <el-container>
      <el-header>
        <h1 style="margin-right: 72px">社区综合治理</h1>
        <el-button @click="tuichu" type="info" style="position: absolute; right: 20px">退出登录</el-button>
        <span style="position: absolute; right: 230px">我是{{ name }}</span>
        <span style="position: absolute; right: 150px">
          <el-image style="width: 50px; height: 50px" :src="this.img"></el-image>
        </span>
      </el-header>

      <el-container>

        <el-aside :width="isCollapse == false ? '200px' : '65px'">
          <el-menu class="el-menu-vertical-demo" :collapse="isCollapse"  background-color="#384DA0"
            text-color="pink" :collapse-transition="false" router>
            <div class="gang" @click="isCollapse = !isCollapse">|||</div>
            <el-submenu v-for="item in list" :key="item._id" :index="item.url">
              <template slot="title">
                <span slot="title">{{ item.name }}</span>
              </template>
              <el-menu-item-group v-for="i in item.children" :key="i._id">
                <el-menu-item :index="i.url">
                  {{ i.name }}
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>

          <div class="clock">
            {{ currentTime1 }}
            <p>{{ currentDate }}</p>
          </div>
        </el-aside>

        <el-main background-color="#FFFFF0">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: false,
      list: [],
      id: '',
      currentTime1: '',
      currentDate: '',
      name: '',
      img: '',
    }
  },
  methods: {
    async getdata() {
      this.img = JSON.parse(sessionStorage.getItem("list")).img
      let id = JSON.parse(sessionStorage.getItem("list")).roleid
      this.name = JSON.parse(sessionStorage.getItem("list")).name
      // console.log(JSON.parse(sessionStorage.getItem("list")));
      let { data } = await this.axios.get(`quanlist?roleid=${id}`)
      this.list = data.data
    },
    tuichu() {
      sessionStorage.clear();
      this.$router.push("/");
    },
    updateTime() {
      const now = new Date();
      this.currentTime1 = now.toLocaleTimeString(); // 格式化时间
    },
    updateDate() {
      this.currentDate = new Date().toISOString().slice(0, 10);
    },
  },
  mounted() {
    this.getdata()
  },
  created() {
    this.updateTime();
    this.updateDate();
    setInterval(this.updateTime, 1000);
  },
  watch: {
    // 如果需要的话，你可以设置一个侦听器来监听特定数据的变化，并更新日期
    // 例如，如果你有一个数据属性表示时区，并且你想根据时区的变化来更新日期
    timeZone: {
      handler() {
        this.updateDate();
      },
      deep: true // 如果timeZone是一个对象或数组，需要设置deep为true来深度监听其变化
    }
  }
}
</script>

<style>
.el-header,
.el-footer {
  background-color: #F4F5F7;

  color: #FF73FF;
  text-align: center;
  width: 100%;
  height: 7vh;
  display: flex;
  align-items: center;
}

.el-aside {
  height: 93vh;
  background: #384DA0;
}

nav {
  width: 80px;
  padding: 20px 0;
  color: rgb(255, 255, 255);
  border-bottom-color: transparent;
  background-color: rgb(43, 47, 58);
}

.clock {
  font-size: 24px;
  font-weight: bold;
  color: gold;
  position: fixed;
  left: 30px;
  bottom: 50px;
}








</style>